package cn.wolfcode.consumer._04_consumer_way;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

/**
 * @Author: 乱梦天真
 * @Description: TODO
 * @Date: 2020/5/10 18:23
 */
public class Consumer {
    //TODO pull方式拉取消息
    public static void main(String[] args) throws Exception {
        //1.创建消费者
        DefaultMQPullConsumer pullConsumer = new DefaultMQPullConsumer("wolfcode_consumer");
        //2.绑定Namesrv
        pullConsumer.setNamesrvAddr("127.0.0.1:9876");
        //3.开启消费者
        pullConsumer.start();
        //4.拉取指定的消息
        PullResult pullResult = pullConsumer.pull(new MessageQueue("04-consumer-way", "broker-a", 2), "*", 0, 3);
        List<MessageExt> msgFoundList = pullResult.getMsgFoundList();
        for (MessageExt messageExt : msgFoundList) {
            System.out.println(new String(messageExt.getBody()));
        }
    }
}